package controller

import (
	"bluebell/logic"
	"bluebell/models"
	"strconv"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// GetPostStatsHandler 获取帖子统计信息
// @Summary 获取帖子统计
// @Description 获取指定帖子的统计数据
// @Tags 统计
// @Accept application/json
// @Produce application/json
// @Param post_id path int true "帖子ID"
// @Success 200 {object} models.PostStats
// @Router /stats/post/{post_id} [get]
func GetPostStatsHandler(c *gin.Context) {
	postID, err := strconv.ParseInt(c.Param("post_id"), 10, 64)
	if err != nil || postID <= 0 {
		ResponseError(c, models.CodeInvalidParam)
		return
	}

	stats, err := logic.GetPostStats(postID)
	if err != nil {
		zap.L().Error("获取帖子统计失败",
			zap.Int64("postID", postID),
			zap.Error(err))
		ResponseError(c, models.CodeServerBusy)
		return
	}

	ResponseSuccess(c, stats)
}
